<?php
/**************************************************************************
 ESAM (EVE to SMF API Module)
 Copyright (C) 2009  Clinton Weiss

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************/

include_once "EsamQuery.php";
include_once "EsamApi.php";

class EsamAlliance
{
	function getAllianceName($allianceID)
	{
		$ea = new EsamApi();
		$allianceXml =  $ea->getAllianceList();
		foreach($allianceXml->result->rowset->row as $allianceRow)
		{
			if ( (string) $allianceRow['allianceID'] == $allianceID )
			{
				return $allianceRow['name'];
			}
		}

		return 0;
	}

	function getAllianceId($allianceName)
	{
		$ea = new EsamApi();
		$allianceXml = $ea->getAllianceList();
		foreach($allianceXml->result->rowset->row as $allianceRow)
		{
			if ( (string) $allianceRow['name'] == $allianceName )
			{
				return $allianceRow['allianceID'];
			}
		}

		return 0;
	}

	function getCorporationName($corporation_id)
	{
		$eve_api = new EsamApi();
		$corp_xml = $eve_api->getCorporationInfo($corporation_id);
		return (string) $corp_xml->result->corporationName;
	}

	function getCharacterName($character_id)
	{
		$eve_api = new EsamApi();
		$xml = $eve_api->getCharacterName($character_id);
		return (string) $xml->result->rowset->row['name'];
	}

	function getFactionWarfareName($fwId)
	{
		switch ($fwId)
		{
			case 500001:
				return 'Caldari State';
			case 500002:
				return 'Minmatar Republic';
			case 500003:
				return 'Amarr Empire';
			case 500004:
				return 'Gallente Federation';
		}
		throw new Exception("Invalid Faction Warfare ID");
	}
}
?>
